# Python 2.6.4
# Project Euler, Problem 84
# Copyright 2010 Talha Zaman

from random import *
board = ['GO', 'A1', 'CC1', 'A2', 'T1', 'R1', 'B1', 'CH1', 'B2', 'B3',
         'JAIL', 'C1', 'U1', 'C2', 'C3', 'R2', 'D1', 'CC2', 'D2', 'D3',
         'FP', 'E1', 'CH2', 'E2', 'E3', 'R3', 'F1', 'F2', 'U2', 'F3',
         'G2J', 'G1', 'G2', 'CC3', 'G3', 'R4', 'CH3', 'H1', 'T2', 'H2']
ch = ['GO', 'JAIL', 'C1', 'E3', 'H2', 'R1', 'RN', 'RN', 'UN', '-3'] + ['*']*6
cc = ['GO', 'JAIL'] + ['*']*14
visit = [0]*40
seed()
shuffle(ch)
shuffle(cc)

pos, dbl = 0, 0
for i in xrange(1000000):
    d1, d2 = randint(1,4), randint(1,4)
    dbl = dbl+1 if d1==d2 else 0
    if dbl==3: dbl, pos = 0, 10
    else: pos = (pos+d1+d2)%40
    if pos==30: pos, dbl = 10, 0
    elif board[pos][0:2]=='CC':
        if cc[0]!='*': pos = board.index(cc[0])
        cc.append(cc.pop(0))
    elif board[pos][0:2]=='CH':
        if ch[0]=='-3': pos -= 3
        elif ch[0]=='RN': pos = (pos+(5-pos%10))%40 if pos%10<5 else (x+(15-pos%10))%40
        elif ch[0]=='UN': pos = 28 if 12<=pos<28 else 12
        elif ch[0]!='*': pos = board.index(ch[0])
        ch.append(ch.pop(0))
    visit[pos]+=1

print visit.index(sorted(visit)[-1])
print visit.index(sorted(visit)[-2])
print visit.index(sorted(visit)[-3])
